package agents;

import constants.*;

import interfaces.ActionInterface;
import interfaces.AgentInterface;
import interfaces.impl.Agent;

import java.awt.Graphics;
import java.util.ArrayList;

import actions.ActionIncreaseMoney;

import objects.SpetialFeature;
import objects.WorldObject;
import universe.Universe;

public class AgentMoney extends Agent implements AgentInterface{
	
	private ActionIncreaseMoney actionIncreaseMoney;
	private double timeToIncreaseMoney=1000;
	private double timeToAct=0;
	
	public AgentMoney(){
		this.id=Constants.AGENT_MONEY;
		
		listActions = new ArrayList<ActionInterface>();
		
		actionIncreaseMoney = new ActionIncreaseMoney(priority);
		listActions.add(actionIncreaseMoney);
		
	}

	@Override
	public void update(WorldObject object, Universe worldI, double time) {
		
		if(!canUpdate(object)){
			System.out.println("Me falta alguna accion para poder actuar");
			return;
		}
		int cont=0;
		
		for(SpetialFeature fe : object.getListFeatures()){
			if(fe.getId()==Constants.SPETIAL_FEATURE_TIME_TO_INCREASE_MONEY){
				timeToIncreaseMoney=fe.getValue();
				cont++;
			}
		}
		
		if(cont!=1){
			System.out.println("NO SE CADA CuANTO ACtuaLIZAR");
			return;
		}
		
		timeToAct=timeToAct+time;
		if(timeToAct>=timeToIncreaseMoney){
			
			actionIncreaseMoney.setPriority(priority);
			actionIncreaseMoney.setSource(object);
			actionIncreaseMoney.setTarget(object);
			object.setImmediatlyActionToDo(actionIncreaseMoney);
			timeToAct=0;
			
		}
		
		
		
	}

	@Override
	public void paint(Graphics g, WorldObject object) {
		// TODO Auto-generated method stub
		int x= (int) (object.getPosition().getX()+object.getImageObject().getImageToShow().getWidth());
		int y= (int) (object.getPosition().getY()+object.getImageObject().getImageToShow().getHeight()/2);
		
		double money=0;
		for(SpetialFeature fe : object.getListFeatures()){
			if(fe.getId()==Constants.SPETIAL_FEATURE_MONEY){
				money = fe.getValue();
			}
		}
		
		g.drawString("Dinero "+money, x, y);
		
		//System.out.println("Pinto el Agent money");
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setName(String name) {
		// TODO Auto-generated method stub
		
	}

}
